Demographics

Row

Sex

Age

League

School

Sport

Sport Level

Row

RTL Summary

RTL Sex

RTL Age

RTL League

RTL School

RTL Sport

RTL Total

Sex

Age

League

Row

RTP Summary

RTP Sex

RTP Age

RTP League

RTP School

RTP Sport

RTL Total

Sex

Age

League

Test One PCSS Summary Scores

Row

Total Symptom Score

Total Symptom Score Summary

Sex

Sex Summary

Age

Age Summary

Row

Headache-Migraine

Headache-Migraine Summary

Sex

Sex Summary

Age

Age Summary

Headache-Migraine Normalized

Headache-Migraine Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Row

Cognitive

Cognitive Summary

Sex

Sex Summary

Age

Age Summary

Cognitive Normalized

Cognitive Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Row

Anxiety-Mood

Anxiety-Mood Summary

Sex

Sex Summary

Age

Age Summary

Anxiety-Mood Normalized

Anxiety-Mood Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Row

Ocular-Motor

Ocular-Motor Summary

Sex

Sex Summary

Age

Age Summary

Ocular-Motor Normalized

Ocular-Motor Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Row

Vestibular

Vestibular Summary

Sex

Sex Summary

Age

Age Summary

Vestibular Normalized

Vestibular Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Row

Sleep

Sleep Summary

Sex

Sex Summary

Age

Age Summary

Sleep Normalized

Sleep Summary Normalized

Sex Normalized

Sex Summary Normalized

Age Normalized

Age Summary Normalized

Models

Row

Sex:Total Symptom Score

---
title: "HCAMP Paper Version 2"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: scroll
    theme: united
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(here)
library(janitor)
library(rio)
library(colorblindr)
library(gghighlight)
library(forcats)
library(ggrepel)
library(knitr)
library(kableExtra)
library(reactable)
library(plotly)
library(glue)
library(fs)
library(rstatix)
library(ggpubr)
library(writexl) 
library(remotes)
library(profvis) 


# theme_fivethirtyeight <- function(base_size = 15, base_family = "") {
#   theme_grey(base_size = base_size, base_family = base_family) %+replace%
#     theme(
# 
#       # Base elements which are not used directly but inherited by others
#       line =              element_line(colour = '#DADADA', size = 0.75,
#                                        linetype = 1, lineend = "butt"),
#       rect =              element_rect(fill = "#F0F0F0", colour = "#F0F0F0",
#                                        size = 0.5, linetype = 1),
#       text =              element_text(family = base_family, face = "plain",
#                                        colour = "#656565", size = base_size,
#                                        hjust = 0.5, vjust = 0.5, angle = 0,
#                                        lineheight = 0.9),
# 
#       # Modified inheritance structure of text element
#       plot.title =        element_text(size = rel(1.5), family = '' ,
#                                        face = 'bold', hjust = -0.05,
#                                        vjust = 1.5, colour = '#3B3B3B'),
#       axis.title.x =      element_text(),
#       axis.title.y =      element_text(),
#       axis.text =         element_text(),
# 
#       # Modified inheritance structure of line element
#       axis.ticks =        element_line(),
#       panel.grid.major =  element_line(),
#       panel.grid.minor =  element_blank(),
# 
#       # Modified inheritance structure of rect element
#       plot.background =   element_rect(),
#       panel.background =  element_rect(),
#       legend.key =        element_rect(colour = '#DADADA'),
# 
#       # Modifiying legend.position
#       legend.position = 'none',
# 
#       complete = TRUE
#     )
# }
# 
# 
# theme_set(theme_fivethirtyeight())


theme_set(theme_minimal(15) +
            theme(legend.position = "bottom",
                  panel.grid.major.x = element_line(color = "gray60"),
                  panel.grid.minor.x = element_blank(),
                  panel.grid.major.y = element_blank())
          )
```

```{r global, include=FALSE}
#all clean sims data
sims_concussion_data <- read_csv(here("data", "sims_concussion_data.csv"))

sims_concussion_data <- sims_concussion_data %>% 
  mutate(age = as.factor(age))

simsimp <- read_csv(here("data", "clean_impact_sims_data.csv"))

str(simsimp)

simsimp <- simsimp %>% 
  mutate(dataset = as.factor(dataset),
         school_year = as.factor(school_year),
         school = as.factor(school),
         league = as.factor(league),
         gender = as.factor(gender),
         age = as.factor(age),
         sport = as.factor(sport),
         injury = as.factor(injury)) %>% 
  mutate_if(is.numeric, round, digits = 3)

```

```{r, include=FALSE}
#helpful functions 

mean_2 <- function(x) {
  z <- na.omit(x)
  sum(z) / length(z)
}

my_mean <- function(x) {
  mean(x[x >= 0], na.rm = TRUE)
}

create_react_time <- function(df, var) {
    df %>% 
      summarize(Mean = mean({{var}}),
                SD = sd({{var}}),
                Min = min({{var}}),
                Max = max({{var}}),
                Total = length({{var}})) %>% 
      mutate_if(is.numeric, round, 2) %>% 
      reactable(columns = list(
        Mean = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        SD = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Min = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Max = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Total = colDef(format = colFormat(separators = TRUE, suffix = " concussions"))
      ))
}

create_react_time2 <- function(df, x, var) {
    df %>% 
    group_by({{x}}) %>% 
      summarize(Mean = mean({{var}}),
                SD = sd({{var}}),
                Min = min({{var}}),
                Max = max({{var}}),
                Total = length({{var}})) %>% 
      mutate_if(is.numeric, round, 2) %>% 
      reactable(columns = list(
        Mean = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        SD = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Min = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Max = colDef(format = colFormat(separators = TRUE, suffix = " days")),
        Total = colDef(format = colFormat(separators = TRUE, suffix = " concussions"))
      ))
}

create_react <- function(df, var) {
    df %>% 
      summarize(Mean = mean({{var}}),
                SD = sd({{var}}),
                Min = min({{var}}),
                Max = max({{var}}),
                Total = length({{var}})) %>% 
      mutate_if(is.numeric, round, 3) %>% 
      reactable(columns = list(
        Mean = colDef(format = colFormat(separators = TRUE)),
        SD = colDef(format = colFormat(separators = TRUE)),
        Min = colDef(format = colFormat(separators = TRUE)),
        Max = colDef(format = colFormat(separators = TRUE)),
        Total = colDef(format = colFormat(separators = TRUE, suffix = " concussions"))
      ))
}


create_react_age <- function(df, var) {
    df %>% 
    group_by(age) %>% 
      summarize(Mean = mean({{var}}),
                SD = sd({{var}}),
                Min = min({{var}}),
                Max = max({{var}}),
                Total = length({{var}})) %>% 
      mutate_if(is.numeric, round, 3) %>% 
      reactable(columns = list(
        Mean = colDef(format = colFormat(separators = TRUE)),
        SD = colDef(format = colFormat(separators = TRUE)),
        Min = colDef(format = colFormat(separators = TRUE)),
        Max = colDef(format = colFormat(separators = TRUE)),
        Total = colDef(format = colFormat(separators = TRUE, suffix = " concussions"))
      ))
}

create_react_gender <- function(df, var) {
    df %>% 
    group_by(gender) %>% 
      summarize(Mean = mean({{var}}),
                SD = sd({{var}}),
                Min = min({{var}}),
                Max = max({{var}}),
                Total = length({{var}})) %>% 
      mutate_if(is.numeric, round, 3) %>% 
      reactable(columns = list(
        Mean = colDef(format = colFormat(separators = TRUE)),
        SD = colDef(format = colFormat(separators = TRUE)),
        Min = colDef(format = colFormat(separators = TRUE)),
        Max = colDef(format = colFormat(separators = TRUE)),
        Total = colDef(format = colFormat(separators = TRUE, suffix = " concussions"))
      ))
}


my_mean(simsimp$dys_btwn_onset_test_4)
```

```{r, include=FALSE}
simsimp %>% 
  count(student_id)

length(unique(simsimp$student_id))
length(unique(simsimp$gender))



simsimp %>% 
  group_by(row, gender) %>% 
  count()
```

# Demographics

Sidebar {.sidebar}
------------

The **Sex** table displays the total number of injuries by sex used in the data set. The total number of injuries is 755 that can be utilized for analysis. Like the previous iteration of the paper, some individuals sustained multiple injuries that are tracked individually. This is a characteristic that one of the reviewers specified we describe more to better explain the sample. The tables displayed present data representing the total number of _injuries_, which include instances of repeat injuries. Data on the number of unique individuals is outlined here: 

  *  **Number of females:** 271
  * **Number of males:** 460
  
  * 260 females sustained one tracked injury
  * 447 males sustained one tracked injury 
  * 10 females sustained two tracked injuries
  * 12 males sustained two tracked injuries
  * 1 female sustained three tracked injuries
  * 1 male sustained three tracked injuries 

Row {.tabset}
-----------------------------------------------------------------------

### Sex 

```{r, include=TRUE}
simsimp %>% 
  group_by(gender) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total)) %>% 
  reactable(
    columns = list(
      gender = colDef(name = "Sex",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE
    )
```

```{r, include=FALSE}
sims_sex <- simsimp %>% 
  group_by(gender) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total))

sims_sex_plot <- ggplot(sims_sex, aes(fct_reorder(gender, total), total)) +
  geom_col(fill = "blue",
           alpha = 0.7) +
  scale_y_continuous(limits = c(0, 600),
                     breaks = c(0, 200, 400, 600)) +
  coord_flip() +
  labs(x = "",
       y = "Total")
```

```{r, include=FALSE}
ggplotly(sims_sex_plot)
```

### Age

```{r, include=TRUE}
simsimp %>% 
  group_by(age) %>% 
  summarize(total = n()) %>% 
  reactable(
    columns = list(
      age = colDef(name = "Age",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE
    )
```

```{r, include=FALSE}
sims_age <- simsimp %>% 
  mutate(age = as.factor(age)) %>% 
  group_by(age) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total))



sims_age_plot <- ggplot(sims_age, aes(fct_reorder(age, total), total)) +
  geom_col(fill = "blue",
           alpha = 0.7) +
  coord_flip() +
  labs(x = "Age",
       y = "Total")
```

```{r, include=FALSE}
ggplotly(sims_age_plot)
```

### League

```{r, include=TRUE}
simsimp %>% 
  group_by(league) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total)) %>% 
  reactable(
    columns = list(
      league = colDef(name = "League",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE
    )
```

### School

```{r}
simsimp %>% 
  group_by(school) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total)) %>% 
  reactable(
    columns = list(
      school = colDef(name = "School",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE,
    searchable = TRUE
    )
```

### Sport

```{r}
simsimp %>% 
  group_by(sport) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total)) %>% 
  reactable(
    columns = list(
      sport = colDef(name = "Sport",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE,
    searchable = TRUE
    )
```

### Sport Level

```{r, include=FALSE}
simsimp %>% 
  group_by(level) %>% 
  summarize(total = n()) %>% 
  arrange(desc(total)) %>% 
  reactable(
    columns = list(
      level = colDef(name = "Level",
                      align = "center"),
      total = colDef(name = "Total",
                     align = "center",
                     format = colFormat(suffix = " injuries"))),
    pagination = TRUE,
    striped = TRUE,
    outlined = TRUE,
    compact = TRUE,
    highlight = TRUE,
    bordered = TRUE
    )
```

Row {.tabset}
-----------------------------------------------------------------------

### RTL Summary 

```{r, include=TRUE}
create_react_time(simsimp, dys_btwn_onset_rtp_3)
```

### RTL Sex

```{r, include=TRUE}
create_react_time2(simsimp, gender, dys_btwn_onset_rtp_3)
```

### RTL Age

```{r, include=TRUE}
create_react_time2(simsimp, age, dys_btwn_onset_rtp_3)
```

### RTL League

```{r, include=TRUE}
create_react_time2(simsimp, league, dys_btwn_onset_rtp_3)
```

### RTL School

```{r, include=TRUE}
create_react_time2(simsimp, school, dys_btwn_onset_rtp_3)
```

### RTL Sport

```{r, include=TRUE}
create_react_time2(simsimp, sport, dys_btwn_onset_rtp_3)
```

```{r, include=FALSE}
rtl_smry_plot <- ggplot(simsimp, aes(dys_btwn_onset_rtp_3)) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 10) +
  labs(x = "Days to Complete RTL",
       y = "Number of Injuries")

rtp_smry_plot <- ggplot(simsimp, aes(dys_btwn_onset_rtp_7)) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 10) +
  labs(x = "Days to Complete RTP",
       y = "Number of Injuries")


rtl_smry_plot2 <- function(df, x, y) {
  p <- ggplot(df, aes({{x}})) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 10)
  p + facet_wrap(vars({{y}})) +
  labs(x = "Days to Complete RTL",
       y = "Number of Injuries")
}

rtp_smry_plot2 <- function(df, x, y) {
  p <- ggplot(df, aes({{x}})) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 10)
  p + facet_wrap(vars({{y}})) +
  labs(x = "Days to Complete RTP",
       y = "Number of Injuries")
}

rtl_smry_plot2(simsimp, dys_btwn_onset_rtp_3, gender)
```

### RTL Total 

```{r, include=TRUE}
ggplotly(rtl_smry_plot)
```

### Sex

```{r, include=TRUE}
ggplotly(rtl_smry_plot2(simsimp, dys_btwn_onset_rtp_3, gender))
```

### Age

```{r, include=TRUE}
ggplotly(rtl_smry_plot2(simsimp, dys_btwn_onset_rtp_3, age))
```

### League

```{r, include=TRUE}
ggplotly(rtl_smry_plot2(simsimp, dys_btwn_onset_rtp_3, league))
```

Row {.tabset}
-----------------------------------------------------------------------

### RTP Summary 

```{r, include=TRUE}
create_react_time(simsimp, dys_btwn_onset_rtp_7)
```

### RTP Sex

```{r, include=TRUE}
create_react_time2(simsimp, gender, dys_btwn_onset_rtp_7)
```

### RTP Age

```{r, include=TRUE}
create_react_time2(simsimp, age, dys_btwn_onset_rtp_7)
```

### RTP League

```{r, include=TRUE}
create_react_time2(simsimp, league, dys_btwn_onset_rtp_7)
```

### RTP School

```{r, include=TRUE}
create_react_time2(simsimp, school, dys_btwn_onset_rtp_7)
```

### RTP Sport

```{r, include=TRUE}
create_react_time2(simsimp, sport, dys_btwn_onset_rtp_7)
```

### RTL Total 

```{r, include=TRUE}
ggplotly(rtp_smry_plot)
```

### Sex

```{r, include=TRUE}
ggplotly(rtp_smry_plot2(simsimp, dys_btwn_onset_rtp_7, gender))
```

### Age

```{r, include=TRUE}
ggplotly(rtp_smry_plot2(simsimp, dys_btwn_onset_rtp_7, age))
```

### League

```{r, include=TRUE}
ggplotly(rtp_smry_plot2(simsimp, dys_btwn_onset_rtp_7, league))
```


# Test One PCSS Summary Scores

Row {.tabset}
-----------------------------------------------------------------------

```{r, include=FALSE}
score_hist <- function(df, x) {
  ggplot(df, aes({{x}})) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 25) +
    labs(x = "Symptom Severity",
         y = "Number of Injuries")
}

gender_hist <- function(df, x) {
  ggplot(df, aes({{x}})) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 25) +
    facet_wrap(~gender) +
    labs(x = "Symptom Severity",
         y = "Number of Injuries")
}

age_hist <- function(df, x) {
  ggplot(df, aes({{x}})) +
  geom_histogram(fill = "#56B4E9",
                color = "white", 
                alpha = 0.9,
                bins = 25) +
    facet_wrap(~age) +
    labs(x = "Symptom Severity",
         y = "Number of Injuries")
}

names(simsimp)
```

### Total Symptom Score 

```{r, include=TRUE}
ggplotly(score_hist(simsimp, total_symptom_score_post_injury_1))
```

### Total Symptom Score Summary

```{r, include=TRUE}
create_react(simsimp, total_symptom_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, total_symptom_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, total_symptom_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, total_symptom_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, total_symptom_score_post_injury_1)
```


Row {.tabset}
-----------------------------------------------------------------------

### Headache-Migraine 

```{r, include=TRUE}
ggplotly(score_hist(simsimp, headache_migraine_cluster_score_post_injury_1))
```

### Headache-Migraine Summary

```{r, include=TRUE}
create_react(simsimp, headache_migraine_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, headache_migraine_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, headache_migraine_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, headache_migraine_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, headache_migraine_cluster_score_post_injury_1)
```

### Headache-Migraine Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, headache_migraine_test_1))
```

### Headache-Migraine Summary Normalized

```{r, include=TRUE}
create_react(simsimp, headache_migraine_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, headache_migraine_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, headache_migraine_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, headache_migraine_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, headache_migraine_test_1)
```

Row {.tabset}
-----------------------------------------------------------------------

### Cognitive

```{r, include=TRUE}
ggplotly(score_hist(simsimp, cognitive_cluster_score_post_injury_1))
```

### Cognitive Summary

```{r, include=TRUE}
create_react(simsimp, cognitive_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, cognitive_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, cognitive_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, cognitive_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, cognitive_cluster_score_post_injury_1)
```

### Cognitive Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, cognitive_test_1))
```

### Cognitive Summary Normalized

```{r, include=TRUE}
create_react(simsimp, cognitive_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, cognitive_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, cognitive_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, cognitive_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, cognitive_test_1)
```


Row {.tabset}
-----------------------------------------------------------------------

### Anxiety-Mood

```{r, include=TRUE}
ggplotly(score_hist(simsimp, anxiety_mood_cluster_score_post_injury_1))
```

### Anxiety-Mood Summary

```{r, include=TRUE}
create_react(simsimp, anxiety_mood_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, anxiety_mood_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, anxiety_mood_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, anxiety_mood_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, anxiety_mood_cluster_score_post_injury_1)
```

### Anxiety-Mood Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, anxiety_mood_test_1))
```

### Anxiety-Mood Summary Normalized

```{r, include=TRUE}
create_react(simsimp, anxiety_mood_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, anxiety_mood_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, anxiety_mood_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, anxiety_mood_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, anxiety_mood_test_1)
```

Row {.tabset}
-----------------------------------------------------------------------

### Ocular-Motor 

```{r, include=TRUE}
ggplotly(score_hist(simsimp, ocular_motor_cluster_score_post_injury_1))
```

### Ocular-Motor Summary

```{r, include=TRUE}
create_react(simsimp, ocular_motor_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, ocular_motor_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, ocular_motor_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, ocular_motor_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, ocular_motor_cluster_score_post_injury_1)
```

### Ocular-Motor Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, ocular_motor_test_1))
```

### Ocular-Motor Summary Normalized

```{r, include=TRUE}
create_react(simsimp, ocular_motor_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, ocular_motor_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, ocular_motor_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, ocular_motor_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, ocular_motor_test_1)
```


Row {.tabset}
-----------------------------------------------------------------------

### Vestibular 

```{r, include=TRUE}
ggplotly(score_hist(simsimp, vestibular_cluster_score_post_injury_1))
```

### Vestibular Summary

```{r, include=TRUE}
create_react(simsimp, vestibular_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, vestibular_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, vestibular_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, vestibular_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, vestibular_cluster_score_post_injury_1)
```

### Vestibular Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, vestibular_test_1))
```

### Vestibular Summary Normalized

```{r, include=TRUE}
create_react(simsimp, vestibular_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, vestibular_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, vestibular_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, vestibular_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, vestibular_test_1)
```


Row {.tabset}
-----------------------------------------------------------------------

### Sleep

```{r, include=TRUE}
ggplotly(score_hist(simsimp, sleep_cluster_score_post_injury_1))
```

### Sleep Summary

```{r, include=TRUE}
create_react(simsimp, sleep_cluster_score_post_injury_1)
```

### Sex

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, sleep_cluster_score_post_injury_1))
```

### Sex Summary

```{r, include=TRUE}
create_react_gender(simsimp, sleep_cluster_score_post_injury_1)
```

### Age

```{r, include=TRUE}
ggplotly(age_hist(simsimp, sleep_cluster_score_post_injury_1))
```

### Age Summary

```{r, include=TRUE}
create_react_age(simsimp, sleep_cluster_score_post_injury_1)
```

### Sleep Normalized

```{r, include=TRUE}
ggplotly(score_hist(simsimp, sleep_test_1))
```

### Sleep Summary Normalized

```{r, include=TRUE}
create_react(simsimp, sleep_test_1)
```

### Sex Normalized

```{r, include=TRUE}
ggplotly(gender_hist(simsimp, sleep_test_1))
```

### Sex Summary Normalized

```{r, include=TRUE}
create_react_gender(simsimp, sleep_test_1)
```

### Age Normalized 

```{r, include=TRUE}
ggplotly(age_hist(simsimp, sleep_test_1))
```

### Age Summary Normalized

```{r, include=TRUE}
create_react_age(simsimp, sleep_test_1)
```


# Models

Sidebar {.sidebar}
------------

Row {.tabset}
-----------------------------------------------------------------------

### Sex:Total Symptom Score

```{r, include=FALSE}
# modeling age:total symptom score model

names(simsimp)

sex_test_1_mod <- lm(dys_btwn_onset_rtp_3 ~ gender*total_symptom_score_post_injury_1, 
                     data = simsimp)


summary(sex_test_1_mod)
confint(sex_test_1_mod)

sex_age_mod <- lm(dys_btwn_onset_rtp_3 ~ gender*age, data = simsimp)

summary(sex_age_mod)

sex_age_test_1_mod <- lm(dys_btwn_onset_rtp_3 ~ 
                            gender*age*total_symptom_score_post_injury_1, 
                          data = simsimp)

summary(sex_age_test_1_mod)

```